package cn.stylefeng.guns.modular.classicCase.controller;

import cn.stylefeng.guns.modular.classicCase.pojo.request.ClassicCaseRequest;
import cn.stylefeng.guns.modular.classicCase.service.ClassicCaseService;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 经典案例控制器
 *
 * @author liuxue
 * @date 2022/01/10 15:10
 */
@RestController
@ApiResource(name = "经典案例")
public class ClassicCaseController {

    @Resource
    private ClassicCaseService classicCaseService;

    /**
     * 添加
     *
     * @author liuxue
     * @date 2022/01/10 15:10
     */
    @PostResource(name = "添加", path = "/classicCase/add")
    public ResponseData add(@RequestBody @Validated(ClassicCaseRequest.add.class) ClassicCaseRequest classicCaseRequest) {
        classicCaseService.add(classicCaseRequest);
        return new SuccessResponseData();
    }

    /**
     * 删除
     *
     * @author liuxue
     * @date 2022/01/10 15:10
     */
    @PostResource(name = "删除", path = "/classicCase/delete")
    public ResponseData delete(@RequestBody @Validated(ClassicCaseRequest.delete.class) ClassicCaseRequest classicCaseRequest) {
        classicCaseService.del(classicCaseRequest);
        return new SuccessResponseData();
    }

    /**
     * 编辑
     *
     * @author liuxue
     * @date 2022/01/10 15:10
     */
    @PostResource(name = "编辑", path = "/classicCase/edit")
    public ResponseData edit(@RequestBody @Validated(ClassicCaseRequest.edit.class) ClassicCaseRequest classicCaseRequest) {
        classicCaseService.edit(classicCaseRequest);
        return new SuccessResponseData();
    }

    /**
     * 查看详情
     *
     * @author liuxue
     * @date 2022/01/10 15:10
     */
    @GetResource(name = "查看详情", path = "/classicCase/detail")
    public ResponseData detail(@Validated(ClassicCaseRequest.detail.class) ClassicCaseRequest classicCaseRequest) {
        return new SuccessResponseData(classicCaseService.detail(classicCaseRequest));
    }

    /**
     * 获取列表
     *
     * @author liuxue
     * @date 2022/01/10 15:10
     */
    @GetResource(name = "获取列表", path = "/classicCase/list")
    public ResponseData list(ClassicCaseRequest classicCaseRequest) {
        return new SuccessResponseData(classicCaseService.findList(classicCaseRequest));
    }

    /**
     * 获取列表（带分页）
     *
     * @author liuxue
     * @date 2022/01/10 15:10
     */
    @GetResource(name = "分页查询", path = "/classicCase/page")
    public ResponseData page(ClassicCaseRequest classicCaseRequest) {
        return new SuccessResponseData(classicCaseService.findPage(classicCaseRequest));
    }

    /**
     * 修改状态
     *
     * @author liuxue
     * @date 2022/01/10 16:44
     */
    @PostResource(name = "修改状态", path = "/classicCase/changeStatus")
    public ResponseData changeStatus(@RequestBody @Validated(ClassicCaseRequest.edit.class) ClassicCaseRequest classicCaseRequest) {

        classicCaseService.edit(classicCaseRequest);
        return new SuccessResponseData();
    }


}